#!/bin/bash
set -e

rm -rf build

mkdir -p build/pk && cd "$_"
`git rev-parse --show-toplevel`/../riscv-pk/configure --host=riscv64-unknown-elf --with-arch=rv64gc_zifencei
make -j4
cd -

mkdir -p build/hello && cd "$_"
riscv64-unknown-elf-gcc -O2 -o hello `git rev-parse --show-toplevel`/ci-tests/hello.c
cd -

mkdir -p build/dummy-slliuw && cd "$_"
riscv64-unknown-elf-gcc -O2 -o dummy-slliuw `git rev-parse --show-toplevel`/ci-tests/dummy-slliuw.c
cd -

mkdir -p build/dummycsr && cd "$_"
riscv64-unknown-elf-gcc -O2 -o customcsr `git rev-parse --show-toplevel`/ci-tests/customcsr.c
cd -

mkdir -p build/atomics && cd "$_"
riscv64-unknown-elf-gcc -O2 -o atomics `git rev-parse --show-toplevel`/ci-tests/atomics.c
cd -


mv build/pk/pk .
mv build/hello/hello .
mv build/dummy-slliuw/dummy-slliuw .
mv build/dummycsr/customcsr .
mv build/atomics/atomics .
tar -cf spike-ci.tar pk hello dummy-slliuw customcsr atomics

rm pk hello dummy-slliuw customcsr atomics
